<?php
class dbModifier{
	
	const database = "dhc";
	const servername = "localhost";
	const username = "dhcuser";
	const password = "greenbanana";
	var $db_connection;

	function __construct(){
		$this->db_connection = new mysqli(self::servername,self::username,self::password,self::database);
		if (mysqli_connect_error()) {
		    die('Connect Error (' . mysqli_connect_errno() . ') '
			    . mysqli_connect_error());
		}
		$this->db_connection->autocommit(FALSE);
		
	}
	
	function prepareStatement($var){
		return $this->db_connection->real_escape_string($var);
	}

	function updateSQLKey($var){
		$this->db_connection->query($var);
		return $this->db_connection->insert_id;	
	}

	function updateSQL($var){
		return $this->db_connection->query($var);
	}

	function execute(){
		try{
			self::commit();
		}catch (Exception $e){
			self::rollback();
		}
	}

	function commit(){
		if(!($this->db_connection->commit())){
			throw new Exception('SQLException');		
		}
	}
	
	function rollback(){
		$this->db_connection->rollback();	
	}

	function __destruct(){
		mysqli_close($this->db_connection);
	}
}
?>
